package cn.healthlink.proxy;
import java.awt.*;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author dengzhiyuan
 * @version 1.0
 * @time 2021/1/20 14:47
 */
public class ProxyInvocationHandler implements InvocationHandler {

	private Object target;

	public ProxyInvocationHandler(Object target) {
		this.target = target;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		System.out.println("开始时间"+ System.currentTimeMillis());
		Object ret = method.invoke(target, args);
		System.out.println("结束时间"+ System.currentTimeMillis());
		return ret;
	}

	public Object getProxy(){
		return Proxy.newProxyInstance(target.getClass().getClassLoader()
				,target.getClass().getInterfaces(),this);
	}

}
